"""Functions for loading Ruin specific resources from the package data"""

import os
from pyre.data import sprite
from ruin import monster, item, terrain

def find_resource(resource_name):
    """
    find_resource(str): str
    Returns the path of a resource named relative path to the ruin package
    """

    dirpath = os.path.dirname(__file__)
    resource_path = os.path.join(dirpath, 'data', resource_name)

    assert os.path.exists(resource_path)
    return resource_path

def resource_prefix():
    return find_resource('')

fontname = find_resource('amstrad.ttf')
menu_data_location = find_resource('menu.dat')
create_monster = monster.MonsterInfo(find_resource('monster.dat')).create
create_item = item.ItemInfo(find_resource('item.dat')).create
terrain_data = terrain.OverworldInfo(find_resource('terrain/overworld.dat'))

def get_sprites(sprite_size):
    sprite_info = sprite.SpriteInfo(find_resource('sprite/sprite.dat'))
    return sprite_info.build_sprite_cache(sprite_size, resource_prefix())
